#ifndef ITEMSMODEL_H
#define ITEMSMODEL_H

#include <deque>
#include <unordered_map>

#include <QAbstractListModel>
#include <QJsonObject>

class Item;
class ItemsModel : public QAbstractListModel
{
    Q_OBJECT
public:
    ItemsModel(QObject *parent = nullptr);
    ItemsModel(size_t bucket_size, QObject *parent = nullptr);
    ~ItemsModel();
public:
    // convenience:
    Item pickFromThisWhichNotCollide(const ItemsModel *other) const;
public:
    // Methods:
    void add(const Item& item);
    void update(const Item &item);
    void remove(const Item& item);
    void clear();
    int size() const;
    bool exist(const Item& item) const;
    bool existId(unsigned long long id) const;
    const Item &ItemsModel::item(unsigned long long id) const;
    const Item &ItemsModel::itemFromIndex(int index) const;
    //Item toMap() const;
private:
    int indexOf(const Item& item) const;
    static unsigned long long idOf(const Item& item);
public:
    virtual int rowCount(const QModelIndex & parent) const override;
    virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
private:
    std::unordered_map<unsigned long long, Item> _items;
};

#endif // ITEMSMODEL_H
